limsOrderTask.PJSampleTaskSearchDetailPage = {

    getBtnToolbar: function (runId) {
        var _this = this;
        var items = [{
            type: 'button',
            text: 'GIKAM.BUTTON.BACK',
            icon: 'back',
            onClick: function () {
                if (_this.param.modal) {
                    Gikam.getLastModal().close()
                } else {
                    workspace.window.goBack()
                }
            }
        },]
        return {
            type: 'btnToolbar',
            items: items
        }
    },

    pjFolderUrl: IFM_CONTEXT + '/secure/basemodule/business/pj-folders',
    pjFolderEquiptUrl: IFM_CONTEXT + '/secure/basemodule/business/pj-folder-equipts',
    pjTaskUrl: IFM_CONTEXT + '/secure/basemodule/business/pj-tasks',
    pjTaskHistoryUrl: IFM_CONTEXT + '/secure/basemodule/business/pj-result-historys',
    auditRecordUrl: IFM_CONTEXT + '/secure/baseline/auditrecord',

    getPrefolderGrid: function () {
        let _this = this
        return {
            type: 'grid',
            id: 'pj-folder-grid',
            url: _this.pjFolderUrl + '/queries',
            requestData: _this.param,
            columns: [{checkbox: true}, {index: true}, {
                field: 'folderCode',
                title: 'T_LIMS_PJ_FOLDER.FOLDERCODE',
                width: 150
            }, {
                field: 'sampleCode',
                title: 'T_LIMS_PJ_FOLDER.SAMPLECODE',
                width: 150
            }, {
                field: 'productName',
                title: 'T_LIMS_PJ_FOLDER.PRODUCTNAME',
                width: 240
            }, {
                field: 'professionalGroup',
                title: 'T_LIMS_PJ_FOLDER.PROFESSIONALGROUP',
                width: 150
            }, {
                field: 'createdTime',
                title: 'T_LIMS_PJ_FOLDER.CREATEDTIME',
                type: 'dateTime',
                width: 150
            }],
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0)
                } else {
                    Gikam.getAsyncComp('folder-equipt-grid').done(grid => {
                        grid.refresh({
                            url: _this.pjFolderEquiptUrl + '/queries',
                            requestData: {
                                folderId_EQ: -1
                            }
                        })
                    })
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('folder-equipt-grid').done(grid => {
                    grid.refresh({
                        url: _this.pjFolderEquiptUrl + '/queries',
                        requestData: {
                            folderId_EQ: row.id
                        }
                    })
                })
            },
        }
    },

    getFolderEquiptGrid: function () {
        let _this = this
        return {
            type: 'grid',
            id: 'folder-equipt-grid',
            columns: [{checkbox: true}, {index: true}, {
                field: 'equipName',
                title: 'T_LIMS_PJ_FOLDER_EQUIP.EQUIPNAME',
                width: 150
            }, {
                field: 'resultStatus',
                title: 'T_LIMS_PJ_FOLDER_EQUIP.RESULTSTATUS',
                width: 150,
                type: 'select',
                search: true,
                category: 'sys',
                param: {
                    codeCategoryId: 'resultstatus'
                },
            }, {
                field: 'createdTime',
                title: 'T_LIMS_PJ_FOLDER_EQUIP.CREATEDTIME',
                type: 'dateTime',
                width: 150
            }],
            url: _this.pjFolderEquiptUrl + '/queries',
            requestData: _this.param,
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0)
                } else {
                    Gikam.getAsyncComp('pj-task-grid').done(grid => {
                        grid.refresh({
                            url: _this.pjTaskUrl + '/queries',
                            requestData: {
                                folderEquipId_EQ: -1
                            }
                        })
                    })
                    Gikam.getAsyncComp('folder-equipt-uploader').done(up => {
                        up.setOptions({
                            bizId: -1
                        })
                    })
                    Gikam.getAsyncComp('pj-task-history-grid').done(grid => {
                        grid.refresh({
                            url: _this.pjTaskHistoryUrl + '/queries',
                            requestData: {
                                folderEquipId_EQ: -1
                            }
                        })
                    })
                    Gikam.getAsyncComp('folder-equipt-record').done(function (grid) {
                        grid.refresh({
                            url: _this.auditRecordUrl + '/queries',
                            requestData: {
                                businessId_SEQ: -1,
                                businessCode_SEQ: 'T_LIMS_PJ_FOLDER_EQUIP'
                            }
                        })
                    })
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('pj-task-grid').done(grid => {
                    grid.refresh({
                        url: _this.pjTaskUrl + '/queries',
                        requestData: {
                            folderEquipId_EQ: row.id
                        }
                    })
                })
                Gikam.getAsyncComp('folder-equipt-uploader').done(up => {
                    up.setOptions({
                        bizId: row.id
                    })
                })
                Gikam.getAsyncComp('pj-task-history-grid').done(grid => {
                    grid.refresh({
                        url: _this.pjTaskHistoryUrl + '/queries',
                        requestData: {
                            folderEquipId_EQ: row.id
                        }
                    })
                })
                Gikam.getAsyncComp('folder-equipt-record').done(function (grid) {
                    grid.refresh({
                        url: _this.auditRecordUrl + '/queries',
                        requestData: {
                            businessId_SEQ: row.id,
                            businessCode_SEQ: 'T_LIMS_PJ_FOLDER_EQUIP'
                        }
                    })
                })
            },
        }
    },

    getPjTaskGrid: function () {
        let _this = this
        return {
            type: 'grid',
            id: 'pj-task-grid',
            columns: [{checkbox: true}, {index: true}, {
                field: 'purposeName',
                title: 'T_LIMS_PJ_TASK.PURPOSENAME',
                width: 200
            }, {
                field: 'methodName',
                title: 'T_LIMS_PJ_TASK.METHODNAME',
                width: 200
            }, {
                field: 'finalResult',
                title: 'T_LIMS_PJ_TASK.FINALRESULT',
                width: 150
            }, {
                field: 'judge',
                title: 'T_LIMS_PJ_TASK.JUDGE',
                width: 150,
                styleFormatter: function (row) {
                    return {backgroundColor: row.color}
                },
            }, {
                field: 'resultStatus',
                title: 'T_LIMS_PJ_TASK.RESULTSTATUS',
                width: 150,
                type: 'select',
                search: true,
                category: 'sys',
                param: {
                    codeCategoryId: 'resultstatus'
                },
            }, {
                field: 'referTip',
                title: 'T_LIMS_PJ_TASK.REFERTIP',
                width: 150
            }],
        }
    },

    getPjTaskHistoryGrid: function () {
        let _this = this
        return {
            type: 'grid',
            id: 'pj-task-history-grid',
            columns: [{checkbox: true}, {index: true}, {
                field: 'oldValue',
                title: 'T_LIMS_PJ_RESULT_HISTORY.OLDVALUE',
                width: 150
            }, {
                field: 'finalResult',
                title: 'T_LIMS_PJ_RESULT_HISTORY.FINALRESULT',
                width: 150
            }, {
                field: 'judge',
                title: 'T_LIMS_PJ_TASK.JUDGE',
                width: 150,
                styleFormatter: function (row) {
                    return {backgroundColor: row.color}
                },
            }, {
                field: 'resultStatus',
                title: 'T_LIMS_PJ_TASK.RESULTSTATUS',
                width: 150,
                type: 'select',
                search: true,
                category: 'sys',
                param: {
                    codeCategoryId: 'resultstatus'
                },
            }, {
                field: 'referTip',
                title: 'T_LIMS_PJ_TASK.REFERTIP',
                width: 150
            }, {
                field: 'createdTime',
                title: 'T_LIMS_PJ_FOLDER_EQUIP.CREATEDTIME',
                type: 'dateTime',
                width: 150
            }],
        }
    },

    getAuditRecordGrid: function () {
        let _this = this
        return {
            type: 'grid',
            id: 'folder-equipt-record',
            columns: [{
                checkbox: true
            }, {
                index: true
            }, {
                field: 'auditStep',
                title: 'T_LIMS_AUDIT_RECORD.AUDITSTEP',
            }, {
                field: 'auditOperation',
                title: 'T_LIMS_AUDIT_RECORD.AUDITOPERATION',
                width: 140
            }, {
                field: 'auditByName',
                title: 'T_LIMS_AUDIT_RECORD.AUDITBYNAME',
            }, {
                field: 'createdTime',
                title: 'T_LIMS_AUDIT_RECORD.CREATEDTIME',
                type: 'dateTime',
                width: 140
            }, {
                field: 'remarks',
                title: 'T_LIMS_AUDIT_RECORD.REMARKS',
            }]
        }
    },

    getEquiptOtherTabs: function () {
        let _this = this
        return {
            type: 'tab',
            panels: [{
                title: 'MODULE.PJ.TIP.PURPOSE',
                items: [_this.getPjTaskGrid()]
            }, {
                title: 'MODULE.PJ.TIP.HIS',
                items: [_this.getPjTaskHistoryGrid()]
            }, {
                title: 'GIKAM.FILE.ATTACHMENT',
                items: [{
                    type: 'uploader',
                    id: 'folder-equipt-uploader',
                    dbTable: 'T_LIMS_PJ_FOLDER_EQUIP',
                    bizId: -1,
                    readonly: true
                }]
            }, {
                title: 'T_CORE_FILE.OPERATE.OPERATION.RECORD',
                items: [_this.getAuditRecordGrid()]
            }]
        }
    },

    create: function () {
        var _this = this
        Gikam.create('layout', {
            id: 'result-edit-layout',
            renderTo: workspace.window.$dom,
            west: {
                width: '30%',
                title: 'T_LIMS_PJ_FOLDER.SERVICE_NAME',
                items: [this.getBtnToolbar(), _this.getFolderEquiptGrid()]
            },
            center: {
                items: [_this.getEquiptOtherTabs()]
                // items: [{
                //     type: 'layout',
                //     north: {
                //         height: '50%',
                //         title: 'T_LIMS_ORDER_TASK.SERVICE_NAME',
                //         items: [_this.getFolderEquiptGrid()]
                //     },
                //     center: {
                //         items: [_this.getEquiptOtherTabs()]
                //     }
                // }]
            }
        })
    },

    init: function (param) {
        this.param = param
        this.create()
    }
}
